import type { TableColumnData } from '@arco-design/web-vue'
import { h, ref } from 'vue'
import { useIssueStore } from '../stores/issueStore'

export function useIssueTable() {
  // const { data, isLoading } = useSearchUser({ role: Role.Student })
  const isLoading = ref(false)
  const { issues } = useIssueStore()

  return {
    isLoading,
    columns: [
      {
        title: '序号',
        dataIndex: 'id',
        width: 150,
        align: 'center',
        sortable: {
          sortDirections: ['ascend', 'descend']
        }
      },
      {
        title: '题目',
        dataIndex: 'title',
        filterable: {
          filter: (value, record) => record.title.includes(value),
          slotName: 'title-filter',
          icon: () => h('i', { class: 'i-uil-search' })
        }
      },
      {
        title: '教师工号',
        width: 140,
        dataIndex: 'teacherID',
        slotName: 'teacherID',
        filterable: {
          filter: (value, record) => record.teacherID.includes(value),
          slotName: 'teacher-id-filter',
          icon: () => h('i', { class: 'i-uil-search' })
        }
      },
      {
        title: '教师姓名',
        dataIndex: 'teacherName',
        width: 140,
        align: 'center',
        filterable: {
          filter: (value, record) => record.teacherName.includes(value),
          slotName: 'teacher-filter',
          icon: () => h('i', { class: 'i-uil-search' })
        }
      },
      {
        title: '选题状态',
        slotName: 'status',
        width: 140,
        align: 'center',
        filterable: {
          filters: [
            {
              text: '已指派',
              value: 'true'
            },
            {
              text: '竞选中',
              value: ''
            }
          ],
          filter: (value, record) => (value.includes('true') ? record.status : !record.status),
          multiple: false
        }
      },
      {
        title: '查看详情',
        width: 140,
        align: 'center',
        slotName: 'action',
        fixed: 'right'
      }
    ] as const satisfies TableColumnData[],
    issues
  }
}
